﻿using System.Configuration;
using Shell.Library.Models;
using Shell.Library.Services;
using Shell.Models;

namespace Shell.Services
{
    /// <summary>
    /// The configuration service is responisble for managing all configurable items in the Orchestra shell.
    /// The application using the Orchestra Shell, can configure it's appearence by using this service.
    /// </summary>
    class ConfigurationService : IConfigurationService
    {
        private AppConfiguration _configuration;
        private ServiceConfiguration _serviceConfiguration;

        /// <summary>
        /// Initializes a new instance of the <see cref="ConfigurationService"/> class.
        /// </summary>
        public ConfigurationService()
        {
            CreateDefaultConfiguration();
        }

        private void CreateDefaultConfiguration()
        {
            _configuration = new AppConfiguration
                {
                    HelpTabText = Shell.Resources.Shell_Resource.HelpButtonText,
                    HelpGroupText = Shell.Resources.Shell_Resource.HelpGroupText,
                    HelpButtonText = Shell.Resources.Shell_Resource.HelpButtonText
                };

            _serviceConfiguration=new ServiceConfiguration();
            _serviceConfiguration.ServiceUrl = ConfigurationManager.AppSettings["WebDataService"];
            if (!_serviceConfiguration.ServiceUrl.EndsWith("/"))
                _serviceConfiguration.ServiceUrl = _serviceConfiguration.ServiceUrl + "/";

        }

        /// <summary>
        /// Gets the configuration object, holding all configarable items.
        /// </summary>
        /// <value>
        /// The configuration.
        /// </value>
        public AppConfiguration Configuration
        {
            get
            {
                if (_configuration == null)
                {
                    CreateDefaultConfiguration();
                }
                return _configuration;
            }
        }

        public ServiceConfiguration ServiceConfig
        {
            get
            {
                if (_serviceConfiguration == null)
                {
                    CreateDefaultConfiguration();
                }
                return _serviceConfiguration;
            }
        }
    }
}
